package com.wang.factory;

public class AbstractFactory {

    public static void main(String[] args) {
        IDataSourceUtil dataSourceUtil = new OracleDataSourceUtil();
        ICommand command = dataSourceUtil.getCommand();
        IConnection connection = dataSourceUtil.getConnection();
        command.command();
        connection.connect();

    }
}

interface IConnection{
    void connect();
}

class MySqlConnection implements IConnection{

    @Override
    public void connect() {
        System.out.println(" mysql connection");
    }
}

class OracleConnection implements IConnection{

    @Override
    public void connect() {
        System.out.println(" Oracle connection");
    }
}

interface ICommand{
    void command();
}

class MysqlCommand implements ICommand{

    @Override
    public void command() {
        System.out.println(" Mysql Command ");
    }
}

class OracleCommand implements ICommand{

    @Override
    public void command() {
        System.out.println(" Oracle Command^");
    }
}

interface IDataSourceUtil{
    IConnection getConnection();
    ICommand getCommand();
}

class MysqlDataSourceUtil implements IDataSourceUtil{

    @Override
    public IConnection getConnection() {
        return new MySqlConnection();
    }

    @Override
    public ICommand getCommand() {
        return new MysqlCommand();
    }
}

class OracleDataSourceUtil implements IDataSourceUtil{

    @Override
    public IConnection getConnection() {
        return new OracleConnection();
    }

    @Override
    public ICommand getCommand() {
        return new OracleCommand();
    }
}